package blo;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import util.Constants;
import dao.LanguagesDAO;
import dto.LanguageDTO;

public class LanguagesBLO {
	public static Logger LOG = Logger.getLogger("blo.LanguagesBLO");
	private LanguagesDAO langDAO = new LanguagesDAO();
	public boolean addLanguage(String name){
		return langDAO.addLanguage(name);
	}
	public boolean removeLanguage(String name) {
		return langDAO.removeLanguage(name);
	}
	public boolean removeLanguage(int langID){
		return langDAO.removeLanguage(langID);
	}
    public String getListHTML(int fromLangID){
    	if(fromLangID < 0) return getListHTML();
    	else {List<LanguageDTO> listLanguage = new ArrayList<LanguageDTO>();
	    	String list = Constants.BLANK_STRING;
	    	listLanguage = langDAO.getAvailableLanguage(fromLangID);
	    	for(int i = 0; i < listLanguage.size(); ++i) {
	    		list +="<option value=" + listLanguage.get(i).getId() +">" + listLanguage.get(i).getName() + "</option>";
	    	}
	    	return list;
    	}
    }
    
    public String getListHTML(){
    	List<LanguageDTO> listLanguage = new ArrayList<LanguageDTO>();
    	String list = Constants.BLANK_STRING;
    	listLanguage = langDAO.getLangList();
    	for(int i = 0; i < listLanguage.size(); ++i) {
    		list +="<option value=" + listLanguage.get(i).getId() +">" + listLanguage.get(i).getName() + "</option>";
    	}
    	return list;
    }

}
